package cz.muni.fi.pa165.travelagency.services;

import cz.muni.fi.pa165.travelagency.dto.PackageTourDTO;
import cz.muni.fi.pa165.travelagency.entities.PackageTour;
import cz.muni.fi.pa165.travelagency.persistence.IPackageTourDAO;
import java.util.ArrayList;
import java.util.List;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Implementation of a services for PackageTour
 *
 * @author Lukas Jungmann
 * @version 1.0
 */
@Service
@Transactional
public class PackageTourService implements IPackageTourService {

    private IPackageTourDAO ptDAO;

    private Mapper mapper;

    @Autowired
    void setPackageTourDao(IPackageTourDAO pt) {
        this.ptDAO = pt;
    }

    @Autowired
    void setMapper(Mapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void createPackageTour(PackageTourDTO pt) {
        ptDAO.createPackageTour(mapper.map(pt, PackageTour.class));
    }

    @Override
    public void updatePackageTour(PackageTourDTO pt) {
        ptDAO.updatePackageTour(mapper.map(pt, PackageTour.class));
    }

    @Override
    public void deletePackageTour(PackageTourDTO pt) {
        ptDAO.deletePackageTour(mapper.map(pt, PackageTour.class));
    }

    @Override
    public PackageTourDTO getPackageTour(Long id) {
        PackageTour pt = ptDAO.getPackageTour(id);
        return pt == null ? null : mapper.map(pt, PackageTourDTO.class);
    }

    @Override
    public List<PackageTourDTO> findAll() {
        List<PackageTour> pts = ptDAO.findAll();
        List<PackageTourDTO> result = new ArrayList<>();
        for (PackageTour pt : pts) {
            result.add(mapper.map(pt, PackageTourDTO.class));
        }
        return result;
    }
}
